/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package web.compliance.mail.browser;

/**
 *
 * @author Aya
 */
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
 
 
@Path("/")
public class WebServices {
    
    private static MailFetcher mf = new MailFetcher();
    
    @Path("verify/{email}/{password}")
    @GET
    public String verify(@PathParam("email") String e, @PathParam("password") String p) {
        if(e.equals("demo") && p.equals("demo"))
            return "true";
        else
            return mf.valid(e, p);
    }
            
    @GET
    @Path("/getmails/{email}/{password}")
    @Produces("application/xml")
    public List<Mail> getMail(@PathParam("email") String e, @PathParam("password") String p) {
        if(e.equals("demo") && p.equals("demo"))
            return mf.getMBox();
        else
            return mf.getGmail(e, p);
    }
    
    @GET
    @Path("/getall")
    @Produces("application/xml")
    public List<Mail> resetFilter() {
        return mf.mail;
    }
    
    @GET
    @Path("/filterbysubject/{keyword}")
    @Produces("application/xml")
    public List<Mail> filterMailsBySubject(@PathParam("keyword") String keyword) {
        return mf.getMailsWithSubject(keyword);
    }
    
    @GET
    @Path("/filterbycontent/{keyword}")
    @Produces("application/xml")
    public List<Mail> filterMailsByContent(@PathParam("keyword") String keyword) {
        return mf.getMailsWithContent(keyword);
    }
    
    @GET
    @Path("/filterbysender/{keyword}")
    @Produces("application/xml")
    public List<Mail> filterMailsBySender(@PathParam("keyword") String keyword) {
        return mf.getMailsWithSender(keyword);
    }
    
    @GET
    @Path("/multifilter/{sender}/{content}/{subject}/{sdate}/{edate}/{keyword}")
    @Produces("application/xml")
    public List<Mail> multifilter(@PathParam("sender") boolean sender, @PathParam("content") boolean content,
                        @PathParam("subject") boolean subject, @PathParam("keyword") String keyword,
                        @PathParam("sdate") String sdate, @PathParam("edate") String edate) {
        if(sdate.equals("null"))
            sdate = null;
        if(edate.equals("null"))
            edate = null;
        return mf.multifilter(sender, content, subject, keyword, sdate, edate);
    }
    
    @GET
    @Path("/multikeywordfilter/{sender}/{content}/{subject}/{sdate}/{edate}")
    @Produces("application/xml")
    public List<Mail> multikeywordfilter(@PathParam("sender") String sender, @PathParam("content") String content,
                        @PathParam("subject") String subject, @PathParam("sdate") String sdate, 
                        @PathParam("edate") String edate) {
        if(sdate.equals("null"))
            sdate = null;
        if(edate.equals("null"))
            edate = null;
        if(sender.equals("null"))
            sender = null;
        if(content.equals("null"))
            content = null;
        if(subject.equals("null"))
            subject = null;
        
        return mf.multiKeywordFilter(sender, content, subject, sdate, edate);
    }
    
    @GET
    @Path("/filterbefore/{date}")
    @Produces("application/xml")
    public List<Mail> filterMailsBeforeDate(@PathParam("date") String date) {
        return mf.getMailsBefore(date);
    }
    
    @GET
    @Path("/filterafter/{date}")
    @Produces("application/xml")
    public List<Mail> filterMailsAfterDate(@PathParam("date") String date) {
        return mf.getMailsAfter(date);
    }
    
    @GET
    @Path("/filterbetween/{startdate}/{enddate}")
    @Produces("application/xml")
    public List<Mail> filterMailsBetweenDate(@PathParam("startdate") String start_date, 
                                                @PathParam("enddate") String end_date) {
        return mf.getMailsBetween(start_date, end_date);
    }
    
}
